<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
					          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
					          xmlns:local="clr-namespace:FileListView.Views"

                    xmlns:vm="clr-namespace:FileListView.ViewModels"
          >
  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="Brushes.xaml" />
  </ResourceDictionary.MergedDictionaries>

  <ControlTemplate x:Key="FilterComboBoxToggleButton" TargetType="ToggleButton">
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition Width="Auto" />
      </Grid.ColumnDefinitions>
      <!-- CornerRadius="2" -->
      <Border x:Name="Border" 
              Grid.ColumnSpan="2"
              Background="{TemplateBinding Background}"
              BorderBrush="{StaticResource FilterCmbNormalBorderBrush}"
              BorderThickness="0" />
      <Border  Margin="2,0" Grid.Column="1" Background="Transparent" BorderBrush="Transparent">
        <Path x:Name="Arrow"
              Fill="{StaticResource FilterCmbGlyphBrush}"
              HorizontalAlignment="Center"
              VerticalAlignment="Center"
              Data="M 0 0 L 4 4 L 8 0 Z"/>
      </Border>
    </Grid>
    <ControlTemplate.Triggers>
      <Trigger Property="ToggleButton.IsMouseOver" Value="true">
        <Setter TargetName="Border" Property="Background" Value="{StaticResource FilterCmbDarkBrush}" />
      </Trigger>
      <Trigger Property="ToggleButton.IsChecked" Value="true">
        <Setter TargetName="Border" Property="Background" Value="{StaticResource FilterCmbPressedBrush}" />
      </Trigger>
      <Trigger Property="IsEnabled" Value="False">
        <Setter Property="Background" Value="{StaticResource FilterCmbDisabledBackgroundBrush}" />
        <Setter Property="BorderBrush" Value="{StaticResource FilterCmbDisabledBorderBrush}" />
        <Setter Property="Foreground" Value="{StaticResource FilterCmbDisabledForegroundBrush}"/>
        <Setter TargetName="Arrow" Property="Fill" Value="{StaticResource FilterCmbDisabledForegroundBrush}" />
      </Trigger>
    </ControlTemplate.Triggers>
  </ControlTemplate>

  <Style x:Key="FilterComboBoxTextBoxStyle" TargetType="{x:Type TextBox}">
    <Setter Property="OverridesDefaultStyle" Value="true"/>
    <Setter Property="AllowDrop" Value="true"/>
    <Setter Property="MinWidth" Value="0"/>
    <Setter Property="MinHeight" Value="0"/>
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
    <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type TextBox}">
          <ScrollViewer x:Name="PART_ContentHost" Background="Transparent" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type local:FilterComboBox}">
    <Setter Property="SnapsToDevicePixels" Value="true"/>
    <!-- Setter Property="OverridesDefaultStyle" Value="true"/ Not sure whether this is required as it causes an error -->
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
    <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
    <!-- Setter Property="BorderBrush" Value="Beige" / -->
    <!-- Setter Property="BorderThickness" Value="2" / -->
    <!-- Setter Property="Background" Value="White" / -->
    <!-- Setter Property="MinWidth" Value="120"/ -->
    <!-- Setter Property="MinHeight" Value="20"/ -->
    <Setter Property="IsEditable" Value="True" />
    <Setter Property="IsTextSearchEnabled" Value="False" />
    <Setter Property="ItemTemplate">
      <Setter.Value>
        <DataTemplate DataType="{x:Type vm:FilterItemViewModel}">
          <Grid ToolTip="{Binding FilterDisplayName}" ToolTipService.IsEnabled="True">
            <TextBlock Text="{Binding FilterText}" />
          </Grid>
        </DataTemplate>
      </Setter.Value>
    </Setter>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type local:FilterComboBox}">
          <Border x:Name="ControlBorder"
                  Background="{TemplateBinding Background}"
							    BorderBrush="{TemplateBinding BorderBrush}"
							    BorderThickness="{TemplateBinding BorderThickness}">

            <Grid>
              <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
              </Grid.ColumnDefinitions>

              <!-- Margin="3,3,23,3" -->
              <ContentPresenter Name="ContentSite"
                                IsHitTestVisible="False" 
                                Content="{TemplateBinding SelectionBoxItem}"
                                ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
                                ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                                
                                HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                                VerticalAlignment="{TemplateBinding VerticalAlignment}"
                                MinWidth="35"
                                Margin="1,0"
                                Grid.Column="0" />

              <TextBox x:Name="PART_EditableTextBox"
                       Style="{StaticResource FilterComboBoxTextBoxStyle}"
                       HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                       HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                       VerticalAlignment="{TemplateBinding VerticalAlignment}"
                       VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                       Margin="1,0"
                       Focusable="True"
                       Visibility="Hidden"
                       IsReadOnly="{TemplateBinding IsReadOnly}" Grid.Column="0">
              </TextBox>

              <ToggleButton Name="ToggleButton"
                            Margin="0"
                            Padding="0"
                            Template="{StaticResource FilterComboBoxToggleButton}" 
                            Grid.Column="1"
                            Focusable="false"
                            VerticalAlignment="Stretch"
                            IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
                            ClickMode="Press">
              </ToggleButton>

              <Popup Name="PART_Popup"
                     Placement="Bottom"
                     IsOpen="{TemplateBinding IsDropDownOpen}"
                     AllowsTransparency="True" 
                     Focusable="False"
                     PopupAnimation="Slide">

                <Grid Name="DropDown"
                      SnapsToDevicePixels="True"                
                      MinWidth="{TemplateBinding ActualWidth}"
                      MaxHeight="{TemplateBinding MaxDropDownHeight}">
                  <Border x:Name="DropDownBorder"
                          Background="{StaticResource FilterCmbWindowBackgroundBrush}"
                          BorderThickness="1"
                          BorderBrush="{StaticResource FilterCmbSolidBorderBrush}"/>

                  <ScrollViewer SnapsToDevicePixels="True">
                    <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
                  </ScrollViewer>
                </Grid>
              </Popup>

            </Grid>
          </Border>

          <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter TargetName="ControlBorder" Property="BorderBrush" Value="{StaticResource FilterCmbHighlighColorBrush}" />
              <Setter TargetName="ToggleButton" Property="Background" Value="{StaticResource FilterCmbDarkBrush}" />
            </Trigger>

            <Trigger Property="HasItems" Value="false">
              <Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
              <Setter Property="Foreground" Value="{StaticResource FilterCmbDisabledForegroundBrush}"/>
            </Trigger>
            <Trigger Property="IsGrouping" Value="true">
              <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
            </Trigger>
            <Trigger SourceName="PART_Popup" Property="Popup.AllowsTransparency" Value="true">
              <Setter TargetName="DropDownBorder" Property="CornerRadius" Value="4"/>
              <Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/>
            </Trigger>
            <Trigger Property="IsEditable"
               Value="true">
              <Setter Property="IsTabStop" Value="false"/>
              <Setter TargetName="PART_EditableTextBox" Property="Visibility"    Value="Visible"/>
              <Setter TargetName="ContentSite" Property="Visibility" Value="Hidden"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

</ResourceDictionary>